package com.citic.netty.client.handler;

import com.citic.netty.client.bootstrap.BootStrapClient;
import com.citic.netty.common.protocol.response.LoginResponsePacket;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class LoginResponseHandler extends SimpleChannelInboundHandler<LoginResponsePacket> {

	@Override
    protected void channelRead0(ChannelHandlerContext ctx, LoginResponsePacket loginResponsePacket) {
        String userId = loginResponsePacket.getUserId();
        String username = loginResponsePacket.getUsername();

        if (loginResponsePacket.isSuccess()) {
        	System.err.println("[" + username + "]登录成功，userId 为: " + userId);
        	BootStrapClient.isLogin = true;
        } 
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) {
    	System.err.println("客户端连接被关闭!");
    }
}
